package com.byd.sealmanage.web;

import com.alibaba.fastjson.JSONObject;
import com.byd.sealmanage.config.CommonResultOutput;
import com.byd.sealmanage.modal.bo.ChangeWorkParamVO;
import com.byd.sealmanage.modal.po.TbUser;
import com.byd.sealmanage.service.WorkManageService;
import com.byd.sealmanage.util.JsonUtil;
import com.byd.sealmanage.util.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/work")
public class WorkManageController {

    @Autowired
    private WorkManageService workManageService;

    /**
     * 获取印章接收页数据
     * @param changeWorkParamVO
     * @return
     */
    @RequestMapping(value = "/getSealChangeData",method = RequestMethod.GET)
    public JSONObject getChangeData(ChangeWorkParamVO changeWorkParamVO){
        TbUser userEntity = ShiroUtils.getUserEntity();
        return workManageService.getChangeDataService(changeWorkParamVO,userEntity);
    }

    /**
     * 获取交接记录页面数据
     * @param changeWorkParamVO
     * @return
     */
    @RequestMapping(value = "/getChangeRecord",method = RequestMethod.GET)
    public JSONObject getChangeRecord(ChangeWorkParamVO changeWorkParamVO){
        TbUser userEntity = ShiroUtils.getUserEntity();
        return workManageService.getChangeRecordService(changeWorkParamVO,userEntity);
    }

    /**
     * 接收印章
     * @param map
     * @return
     */
    @RequestMapping(value = "/receiveDivisionSeal",method = RequestMethod.POST)
    public JSONObject receiveDivisionSeal(@RequestBody Map map){
        JSONObject jsonObject;
        try{
            jsonObject = workManageService.receiveDivisionSealService(map.get("changeId").toString());
        }catch(Exception e){
            CommonResultOutput commonResultOutput = new CommonResultOutput("9999","接收失败，请刷新页面重试！");
            jsonObject = JsonUtil.toJSONObject(commonResultOutput);
        }
        return jsonObject;
    }

    /**
     * 退回印章
     * @return
     */
    @RequestMapping(value = "/refuseDivisionSeal",method = RequestMethod.POST)
    public JSONObject refuseDivisionSeal(@RequestBody Map map){
        JSONObject jsonObject;
        try{
            jsonObject = workManageService.refuseDivisionSealService(map.get("changeId").toString());
        }catch(Exception e){
            CommonResultOutput commonResultOutput = new CommonResultOutput("9999","退回失败，请刷新页面重试！");
            jsonObject = JsonUtil.toJSONObject(commonResultOutput);
        }
        return jsonObject;
    }
}
